
/**		
 * 
 *	uk.co.lmfm.guppy.controller.SDKDownloadCompleteCommand
 *	
 *	@version 1.00 | Jan 29, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.controller 
{
	import uk.co.lmfm.guppy.model.LibraryProxy;
	import org.osflash.thunderbolt.Logger;
	import uk.co.lmfm.guppy.application.enum.ApplicationConstants;
	import uk.co.lmfm.guppy.model.SettingsProxy;
	import uk.co.lmfm.guppy.model.vo.AppStateVO;
	import uk.co.lmfm.guppy.model.vo.FlexSDKVO;
	import uk.co.lmfm.guppy.view.ProjectMediator;

	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	/**
	 * SDKDownloadCompleteCommand
	 */
	public class SDKDownloadCompleteCommand extends SimpleCommand implements ICommand 
	{
		override public function execute(notification : INotification) : void
		{
			super.execute(notification);
			
			var settingsProxy : SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;
			var libraryProxy:LibraryProxy = facade.retrieveProxy(LibraryProxy.NAME) as LibraryProxy;
			var appState : AppStateVO = settingsProxy.readAppState();

			//var sdks : Vector.<FlexSDKVO> = notification.getBody() as Vector.<FlexSDKVO>;			var sdks : Vector.<FlexSDKVO> = libraryProxy.flexSDKs;
			var data : String = '';
			
			for (var i : int = 0;i < sdks.length;i++)
			{
				data += sdks[i].url + (i < sdks.length - 1 ? ',' : '');
			}
			
			appState.sdks = data;
			settingsProxy.writeAppState(appState);
			libraryProxy.configureLibrary(settingsProxy.readSettings());
			
			Logger.info("Currently installed SDKs: " + data);
			
			sendNotification(ApplicationConstants.CHANGE_VIEW, ProjectMediator.NAME);
			sendNotification(ApplicationConstants.ENABLE_MENU);
		}
	}
}
